<template>
  <div>
    <BaseModal @onSubmit="onSubmit" @onClose="onClose" :show="show" title="编辑学校">
      <div class="demo-input-suffix">
        <span class="form-input-label">学校名称：</span>
        <el-input v-model="data.school_name" placeholder="请输入学校名称"></el-input>
      </div>
    </BaseModal>
  </div>
</template>
<script>
import modalClose from "@/mixins/modalClose";
import { schoolModel } from "@/api/models";
import { Message } from "element-ui";
export default {
  mixins: [modalClose],
  components: {},
  data() {
    return {
      data: {
        school_id: null,
        school_name: ''
      }
    };
  },
  props: {
    obj: null
  },
  watch: {
    obj: function(value) {
      if(value.school_name) {
        this.data = {
          school_id: value.school_id,
          school_name: value.school_name
        }
      }
    }
  },
  mounted() {},
  methods: {
    onSubmit() {
      let d = this.data;
      if (!d.school_name) {
        return Message.warning("请填完整信息");
      }
      if(d.school_id) {
        schoolModel.update(d.school_id, d, res => {
          Message.success(res.message);
          this.onClose();
          this.$emit('afterSubmit');
        })
      }else{
        schoolModel.create(d, res => {
          Message.success(res.message);
          this.onClose();
          this.$emit('afterSubmit');
        })
      }
    },
    onClose() {
      this.$emit("onClose");
    }
  }
};
</script>
<style lang="scss">
</style>